<?php
/**
* testdbMasterSchedule class for Forestdale 
* @version April 16, 2014
*/

include_once(dirname(__FILE__).'/../domain/MasterScheduleEntry.php');
include_once(dirname(__FILE__).'/../database/dbMasterSchedule.php');

define ("ID","weeklymonodd-9-14-cln1");

echo("starting dbMasterSchedule test </br>");
testInsert();
testRetrieve();
testUpdate();
testGetMasterShifts();

function testInsert() {
    $ms = new MasterScheduleEntry("weekly", "mon", "odd", "9", "14", "cln1", "notes here", ID);

    echo 'will test insert_dbMasterSchedule </br>';
    $result = insert_dbMasterSchedule($ms);
    
    echo 'result is ' . $result.'</br>';
    if ($result)
        echo "clinician inserted </br>";
    else
        echo "clinician not inserted</br>";
    
    echo "test data: " . $ms->get_clinician_ID() . "</br>";
    echo "test data: " . $ms->get_day()  . "</br>";
    echo "test data: " . $ms->get_week_no()  . "</br>";

   $res = delete_dbMasterSchedule(ID);
    if ($res == null)
        echo 'Retrieve failed</br>';
}

function testRetrieve() {
    $ms = new MasterScheduleEntry("weekly", "mon", "odd", "9", "14", "cln1", "notes here", ID);
    
    echo 'will test retrieve_dbMasterSchedule </br>';
    $result = insert_dbMasterSchedule($ms);
   //  echo 'result is ' . $result.'</br>';
    if ($result)
        echo "clinician inserted </br>";
    else
        echo "clinician not inserted</br>";

    $ms = retrieve_dbMasterSchedule("mon", "odd");
    if ($ms == null)
        echo 'Retrieve failed</br>';
    echo count($ms)."Master Schedule Entries Retrieved</br>";

    echo "retrieve test done...";
    
    $res = delete_dbMasterSchedule(ID);
    if ($res == null)
        echo 'Delete failed</br>';
}

function testUpdate() {
    $ms = new MasterScheduleEntry("weekly", "mon", "odd", "9", "14", "cln1", "notes here", ID);
    
    echo 'will test update_dbMasterSchedule </br>';
    
    $result = insert_dbMasterSchedule($ms);
    //echo 'result is ' . $result.'</br>';
    if ($result)
        echo "clinician inserted </br>";
    else
        echo "clinician not inserted</br>";
    
    $res = update_dbMasterSchedule($ms);
    if ($ms == null)
        echo 'Update failed</br>';
    
    echo "update test done...";

    $res = delete_dbMasterSchedule(ID);
    if ($res == null)
        echo 'Delete failed</br>';
    
}

function testGetMasterShifts() {
    $ms = new MasterScheduleEntry("weekly", "mon", "odd", "9", "14", "cln1", "notes here", ID);
    
    echo 'will test getMasterShifts </br>';
    $result = insert_dbMasterSchedule($ms);
   // echo 'result is ' . $result.'</br>';
    if ($result)
        echo "schedule entry inserted </br>";
    else
        echo "schedule entry not inserted</br>";

   // $ms = retrieve_dbMasterSchedule(ID, "9");
    $mseList= get_master_shifts('weekly','odd' , 'mon');
   if  (count($mseList)==0)
       echo 'no records retrieved</br>';

  else
   {
      echo count($mseList).' records were retrieved'.'</br>';
       for ($i=0;$i<count($mseList);$i++)
           echo $mseList[$i]->get_id().'</br>';
   }
   
    $res = delete_dbMasterSchedule(ID);
    if ($res == null)
        echo 'Delete failed</br>';
}
?>